"use strict";
/**
 * @ Author: Yoann Meclot. MSay2
 * @ Created on: 2020-09-02 15:44:37
 * @ Modified on: 2021-06-14 18:30:05
 *
 * @version 1.0
 */
/**
 * Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.TSField = void 0;
const ArrayList_js_1 = require("../util/list/ArrayList.js");
const Arrays_js_1 = require("../util/list/Arrays.js");
const Utils_js_1 = require("../util/Utils.js");
/**
 * TSField object allows you to write a field.
 *
 * Use static field to initialize the field to undefined value.
 *
 * @class `TSField`
 * @version 1.0
 */
class TSField {
    constructor(builder) {
        this.mName = Utils_js_1.Preconditions.checkNotNull(builder.mName, "field name", "name");
        this.mType = Utils_js_1.Preconditions.checkNotNull(builder.mType, "field type", "type");
        this.mDocs = builder.mDocs;
        this.mModifiers = builder.mModifiers;
        this.mImports = builder.mImports;
        this.mValue = builder.mValue;
        this.mAnnotations = builder.mAnnotations;
    }
    /**
     * Build field.
     *
     * @param name The name of the field.
     * @type {TSField.Builder}
     * @since 1.0
     */
    static fieldBuilder(name) {
        return new TSField.Builder(name);
    }
    emit(codeWriter) {
        codeWriter.emitField(this);
        return codeWriter;
    }
}
exports.TSField = TSField;
/**
 * Static field to init your field to undefined value.
 */
TSField.UNDEFINED = "msay2.tspoet:UNDEFINED";
TSField.Builder = class Builder {
    constructor(name) {
        this.mImports = new ArrayList_js_1.ArrayList();
        this.mDocs = new ArrayList_js_1.ArrayList();
        this.mAnnotations = new ArrayList_js_1.ArrayList();
        this.mModifiers = new ArrayList_js_1.ArrayList();
        this.mName = name;
    }
    /**
     * Add modifiers.
     *
     * @param modifiers The modifiers to be added.
     * @throws {TSPoetException} Check if the modifiers is undefined or null.
     * @type {TSField.Builder}
     * @since 1.0
     */
    addModifiers(...modifiers) {
        this.mModifiers = Arrays_js_1.Arrays.asList(Utils_js_1.Preconditions.checkNotNull(modifiers, "field modifiers", "modifiers"));
        return this;
    }
    /**
     * add annotation.
     *
     * @param tsAnnotation The annotation to be added.
     * @throws {TSPoetException} Check if the annotation is undefined or null.
     * @type {TSField.Builder}
     * @since 1.0
     */
    addAnnotation(tsAnnotation) {
        this.mAnnotations.add(Utils_js_1.Preconditions.checkNotNull(tsAnnotation, "field annotation", "TSAnnotation object"));
        for (let entry of tsAnnotation.mImports.entries())
            this.putImport(entry.getValue());
        return this;
    }
    /**
     * Add a documentation.
     *
     * @param arg Your comment.
     * @type {TSField.Builder}
     * @since 1.2
     */
    addDoc(arg) {
        this.mDocs.add(Utils_js_1.Preconditions.checkNotNull(arg, "field documentation", "string argument"));
        return this;
    }
    /**
     * Specify a return type.
     *
     * @param objectName The return type.
     * @throws {TSPoetException} Check if the ObjectName object is undefined or null.
     * @type {TSField.Builder}
     * @since 1.0
     */
    return(objectName) {
        this.mType = Utils_js_1.Preconditions.checkNotNull(objectName, "field type", "type");
        this.putImport(objectName);
        return this;
    }
    /**
     * Set a value.
     *
     * @param value The value of the field.
     * @type {TSField.Builder}
     * @since 1.0
     */
    setValue(value) {
        this.mValue = value;
        return this;
    }
    /**
     * Build field.
     *
     * @throws {TSPoetException} Check if the name is undefined or null.
     * @throws {TSPoetException} Check if the type is undefined or null.
     * @type {TSField}
     * @since 1.0
     */
    build() {
        return new TSField(this);
    }
    putImport(objectName) {
        this.mImports.add(objectName);
    }
};
//# sourceMappingURL=TSField.js.map